//
//  NSBundle+WHSLocalizablePath.m
//  WHStudy
//
//  Created by GeDaTing on 2021/8/21.
//

#import "NSBundle+WHSLocalizablePath.h"
#import "WHSLocalizableConfig.h"

static NSBundle *whsLocalizableBundle = nil;

@implementation NSBundle (WHSLocalizablePath)
+ (NSBundle *)whs_getLocalizableBundle
{
    if (whsLocalizableBundle == nil) {
        whsLocalizableBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"WHStudyLocalizable.bundle" ofType:nil]];
    }
    return whsLocalizableBundle;
}

+ (NSBundle *)whs_getLocalizableLprojBundle
{
    NSString *language = [WHSLocalizableConfig whs_getLanguage];
    if (![language isKindOfClass:NSString.class] || language.length < 2) {
        language = @"zh";
    }
    NSString *lprojName = [language substringWithRange:NSMakeRange(0, 2)] ?: @"zh";
    NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle whs_getLocalizableBundle] pathForResource:lprojName ofType:@"lproj"]];
    return bundle;
}

@end
